package cn.edu.xmu.restfuldemo.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 22920192204242
 * @date 2021/10/14 16:53
 */
@Data
@ApiModel(description = "订单对象")
public class OrdersRetVo {


    @ApiModelProperty(value = "主键")
    private Integer id;

    @ApiModelProperty(value = "订单号")
    private String orderSn;
    @ApiModelProperty(value = "父订单id")
    private Integer pid;
    @ApiModelProperty(value = "订单类型")
    private Integer orderType;
    @ApiModelProperty(value = "订单主状态")
    private Integer state;
    @ApiModelProperty(value = "订单子状态")
    private Integer subState;
    private String gmtCreate;


    private String gmtModified;
    @ApiModelProperty(value = "购买者id")
    private Integer customerId;
    @ApiModelProperty(value = "店铺id")
    private Integer shopId;

    @ApiModelProperty(value = "收货人")
    private String consignee;
    @ApiModelProperty(value = "地区id")
    private Integer regionId;
    @ApiModelProperty(value = "收货详细地址")
    private String address;
    @ApiModelProperty(value = "联系电话")
    private String mobile;
    @ApiModelProperty(value = "附言")
    private String message;
    @ApiModelProperty(value = "运费")
    private Double freightPrice;
    @ApiModelProperty(value = "使用的优事卷id")
    private Integer couponId;
    @ApiModelProperty(value = "优惠卷/优惠活动折扣数额")
    private String discountPrice;
    @ApiModelProperty(value = "订单商品优惠前总额")
    private Integer originPrice;
    @ApiModelProperty(value = "预售活动id")
    private Integer presaleId;
    @ApiModelProperty(value = "团购活动id")
    private Integer grouponId;
    @ApiModelProperty(value = "返给分享者的点数")
    private Integer rebateNum;
    @ApiModelProperty(value = "发货时间")
    private String confirmTime;
    @ApiModelProperty(value = "快递单号")
    private String shipmentSn;
    @ApiModelProperty(value = "优惠啊券活动ID")
    private Integer couponActivityId;//优惠活动ID
    @ApiModelProperty(value = "团购折扣")
    private Integer grouponDiscount; //团购折扣


    @ApiModelProperty(value = "买家逻辑删除")
    private Boolean beDeleted;

    private List<OrderItemRetVo> orderItems;

    public OrdersRetVo(Orders orders){
        this.couponActivityId = orders.getCouponActivityId();
        this.grouponDiscount = orders.getGrouponDiscount();
        this.id = orders.getId();
        this.orderSn = orders.getOrderSn();
        this.pid = orders.getPid();
        this.orderType = orders.getOrderType();
        this.state = orders.getState();
        this.subState = orders.getSubState();
        this.gmtCreate = orders.getGmtCreate();
        this.gmtModified = orders.getGmtModified();
        this.customerId = orders.getCustomerId();
        this.shopId = orders.getShopId();
        this.consignee = orders.getConsignee();
        this.regionId = orders.getRegionId();
        this.address = orders.getAddress();
        this.mobile = orders.getMobile();
        this.message = orders.getMessage();
        this.freightPrice = orders.getFreightPrice();
        this.couponId = orders.getCouponId();
        this.discountPrice = orders.getDiscountPrice();
        this.originPrice = orders.getOriginPrice();
        this.presaleId = orders.getPresaleId();
        this.grouponId = orders.getGrouponId();
        this.rebateNum = orders.getRebateNum();
        this.confirmTime = orders.getConfirmTime();
        this.shipmentSn = orders.getShipmentSn();
        this.beDeleted = orders.getBeDeleted();
        if (null != orders.getOrderIterms()) {
            List<OrderItemRetVo> orderItems = new ArrayList<>(orders.getOrderIterms().size());

            for (OrderItem orderItem : orders.getOrderIterms()) {
                OrderItemRetVo orderItemRetVo = new OrderItemRetVo(orderItem);
                orderItems.add(orderItemRetVo);
            }
            this.orderItems = orderItems;
        }
    }


}
